package com.chizha.controller;

import com.chizha.common.MD5Util;
import com.chizha.common.ParamValidator;
import com.chizha.service.LoginService;
import com.jfinal.aop.Before;
import com.jfinal.core.Controller;
import com.jfinal.plugin.activerecord.Record;

/**
 * 本 demo 仅表达最为粗浅的 jfinal 用法，更为有价值的实用的企业级用法
 * 详见 JFinal 俱乐部: http://jfinal.com/club
 * 
 * IndexController
 */
public class loginController extends Controller {
	
	static LoginService service = new LoginService();
	
	public void index() {
		render("login.html");
	}
	
	@Before(ParamValidator.class)
	public void loginCheck(){
		String code = getPara("code");
		String password = MD5Util.getMD5(getPara("password"));
		Record userInfo = service.login(code, password);
		getSession().setAttribute("userInfo", userInfo);
		getSession().setMaxInactiveInterval(3600*5);
		redirect("/user");
	}
}





